package com.example.utils;



import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;

@Controller
public class FTPTest {

    public static void main(String[] args){
        try{
            FTPClient ftpClient =new FTPClient();
            ftpClient.connect("192.168.238.1",21);
            boolean state = ftpClient.login("anonymous","851523232@qq.com");
            int replyCode =ftpClient.getReplyCode();
            if (FTPReply.isPositiveCompletion(replyCode)){
                ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
                ftpClient.makeDirectory("img");
                ftpClient.changeWorkingDirectory("img");
                FileInputStream fileInputStream = new FileInputStream("C:\\Users\\小刀\\Desktop\\img\\01.jpg");

                ftpClient.storeFile(new String("测试.jpg".getBytes("GBK"),"iso-8859-1"),fileInputStream);
                ftpClient.logout();
                System.out.println("finsh..");
            }
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}
